package com.uni.utils;

import com.uni.pojo.Address;
import lombok.extern.log4j.Log4j2;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Author:      Unirithe/Mr.Chao
 * CSDN:        https://blog.csdn.net/Unirithe
 * CreatedTime:  2022/2/9 16:11
 **/
@Log4j2
public class UserInfoUtil {
    public static String encodeAddress(Address addr){
        return String.join("-", addr.getProv(), addr.getCity(), addr.getArea(), addr.getDetail());
    }
    public static Address decodeAddress(String addr){
        String[] a = addr.split("-");
        return (a != null && a.length == 4) ?
                new Address(a[0], a[1], a[2], a[3]) : null;
    }
    public static Date encodeBirthday(String birthdayString){
        try {
            return new Date(String.valueOf(new SimpleDateFormat("yyyy-MM-dd").parse(birthdayString)));
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }
    public static String decodeBirthday(Date birthday ){
        return new SimpleDateFormat("yyyy-MM-dd").format(birthday);
    }

}
